package cn.daniellee.plugin.ea.listener;

import cn.daniellee.plugin.ea.ExplodeAlone;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;

public class EntityListener implements Listener {

	@EventHandler
	public void onEntityExplode(EntityExplodeEvent e) {
		World world = e.getLocation().getWorld();
		if (world != null && ExplodeAlone.getInstance().getWorlds().contains(world.getName())) {
			e.blockList().removeIf(item -> item.getType() == Material.TNT);
			e.getEntity().getNearbyEntities(3, 3, 3).forEach(item -> {
				if (item.getType() == EntityType.MINECART_TNT) item.remove();
			});
		}
	}

}
